/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src;
/**
 *
 * @author  G. Cherencio
 */
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.helpers.DefaultHandler;

public class ReadXMLFile {

    private DefaultHandler handler = null;
    private SAXParserFactory factory = null;
    private SAXParser saxParser = null;
    private String xmlFile = null;

    public ReadXMLFile(final String file) {
        try {
            xmlFile = file;
            factory = SAXParserFactory.newInstance();
            saxParser = factory.newSAXParser();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setHandler(DefaultHandler h) {
        handler = h;
    }

    public DefaultHandler getHandler() {
        return handler;
    }

    public void start() {
        if (handler != null && saxParser != null) {
            try {
                saxParser.parse(xmlFile, handler);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}